﻿using System.ComponentModel;
using JetBrains.Application;
using JetBrains.ProjectModel;
using JetBrains.Util;
using JetBrains.VsIntegration.ProjectModel.PropertiesExtender;

namespace GammaJul.ReSharper.GammaXaml.Caliburn {

	public class CaliburnSupportTypeConverter : StringConverter {

		public const string Auto = "Auto";
		public const string Yes = "Yes";
		public const string No = "No";

		public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
			IProject project = null;
			var shellLocks = Shell.Instance.GetComponent<IShellLocks>();
			VSExtenderUtils.ExecuteReadLock(
				shellLocks,
				"CaliburnSupportTypeConverter.GetStandardValues",
				() => project = ProjectPropertiesExtenderProviderBase.FindProject(context.Instance));

			string[] values;
			if (project == null)
				values = EmptyArray<string>.Instance;
			else {
				values = new[] {
					Auto,
					Yes,
					No
				};
			}
			return new StandardValuesCollection(values);
		}

		public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) {
			return true;
		}

		public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
			return true;
		}

	}

}